package com.ui.mine.view;

import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.base.BaseContract;
import com.base.BaseSlideOutActivity;
import com.ddd.wandemo.R;

public class LoginAndRegisterActivity extends BaseSlideOutActivity {
    public static final int LOGIN = 10000;
    public static final int REGISTER = 10001;
    private Toolbar mToolbar;
    private int mType;


    @Override
    protected int setLayoutId() {
        return R.layout.activity_login_register;
    }

    @Override
    protected void initView() {
        mType = getIntent().getIntExtra("type", 0);
        mToolbar = findViewById(R.id.toolbar);
        initToolBar();

    }

    @Override
    protected void initEvent() {
        LoginFragment loginFragment = new LoginFragment();
//        RegisterFragment registerFragment = new RegisterFragment();
        Bundle args = new Bundle();
        switch (mType) {
            case LOGIN:
                args.putInt("type",LOGIN);
                break;
            case REGISTER:
                args.putInt("type",REGISTER);
                break;
            default:
                break;
        }
        loginFragment.setArguments(args);
        getSupportFragmentManager().beginTransaction().add(R.id.fl_contain, loginFragment).commit();
    }

    @Override
    protected BaseContract.RootPresenter initPresenter() {
        return null;
    }

    private void initToolBar() {
//        String title;
//        if (mType == LOGIN) {
//            title = "登录";
//        } else {
//            title = "注册";
//        }
        mToolbar.setTitle("登录");
        //根据主题设置返回键
        TypedArray array = getTheme().obtainStyledAttributes(new int[]{
                R.attr.back_icon
        });
        int backIcon = array.getResourceId(0, 0);

        mToolbar.setNavigationIcon(backIcon);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
